package top.yamhk.agent.entity.enums;

/**
 * 错误码枚举类
 *
 * @author 庆 HongKong
 * @date 2019/4/14 19:03
 */
public enum ErrorCodes {
    /**
     * 请求成功
     */
    SUCCESS("000000", "success"),
    ERROR_SIMPLE("111111", "Lack of key information"),
    DATA_NOT_EXISTS("001000", "DATA", "数据不存在"),
    DATA_REPEAT("001001", "DATA", "数据重复"),
    /**
     * 未知错误
     */
    UN_KNOW_ERROR("000500", "un-know-error"),

    USER_NO_LOGIN("001001", "USER", "accessToken in head is necessary"),
    USER_LOGIN_EXPIRED("001002", "USER", "accessToken have expired"),
    USER_TOKEN_CHECK_ERROR("000005", "USER", "accessToken check error"),

    USER_WRONG_NAME("000005", "USER", "用户名不存在，请确认用户名！"),
    USER_EXPIRE("000005", "USER", "用户名不存在，请确认用户名！"),

    DOWNLOAD_FILE_NOT_EXIST("000003", "WEB", "file not exist."),
    FORBIDDEN_ACCESS_ERROR("000004", "WEB", "没有服务访问权限"),

    SEND_SMS_ERROR("000005", "SERVER", "短信发送失败！"),
    DATA_ALREADY_EXISTS("000005", "DAO", "The data need to be added already exists!");

    private final String code;
    private final String message;
    private final String module;

    ErrorCodes(String code, String module, String message) {
        this.code = code;
        this.module = module;
        this.message = message;
    }

    ErrorCodes(String code, String message) {
        this.module = "SYS";
        this.code = code;
        this.message = message;
    }

    public static String getModule(String code) {
        ErrorCodes[] var1 = values();
        int var2 = var1.length;

        for (ErrorCodes msg : var1) {
            if (msg.getCode() == code) {
                return msg.getModule();
            }
        }
        return "Unknown";
    }

    public String getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public String getModule() {
        return null != this.module ? this.module.toUpperCase() : null;
    }

    @Override
    public String toString() {
        return String.valueOf(this.getCode());
    }
}